# -*- coding: utf-8 -*-
#   基础record
# @Time    ： 2023/1/30  17:48
# @Auther  ： 徐良
# File     :  baseRecord.py
from share.baseFunction import getInstanceType


class BaseRecord(object):

    def __init__(self, fieldList, fieldListVal, typeList=None):
        if typeList is not None:
            for name, val, stype in zip(fieldList, fieldListVal, typeList):
                name = name.lower().strip()
                if stype.lower() == 'integer':
                    if val == '':
                        v = 0
                    else:
                        v = int(val)
                elif stype.lower() == 'decimal':
                    if val == '':
                        v = 0.0
                    else:
                        v = float(val)
                else:
                    v = val

                self.__dict__[name] = v
        else:
            for name, val in zip(fieldList, fieldListVal):
                name = name.lower().strip()
                if getInstanceType(val) == 'int':
                    if val == '':
                        v = 0
                    else:
                        v = int(val)
                elif getInstanceType(val) == 'float':
                    if val == '':
                        v = 0.0
                    else:
                        v = float(val)
                else:
                    v = val

                self.__dict__[name] = v

    def __hash__(self):
        return super(BaseRecord, self).__hash__()

    def __lt__(self, other):
        return bool(self.Fnumber.lower() < other.Fnumber.lower())

    def __eq__(self, other):
        return bool(self.Fnumber.lower() == other.Fnumber.lower())

    def getHash(self):
        return self.__hash__()

    def value(self, fieldName):     # 不可以加@staticmethod
        f = fieldName.lower().strip()
        ret = self.__dict__[f]
        return ret
